package cc.telecomdigital.tdstock.adapter;

import java.util.List;

import android.graphics.Color;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cc.telecomdigital.tdstock.R;

public class MoreItemAdapter extends BaseAdapter
{
	private LayoutInflater			minflater;
	private List<ViewHolderWithIcon>	list;

	public MoreItemAdapter(LayoutInflater inflater,
			List<ViewHolderWithIcon> list)
	{
		super();
		this.minflater = inflater;
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return position < this.list.size() ? this.list.get(position) : null;
	}

	@Override
	public long getItemId(int position)
	{
		return position < this.list.size() ? this.list.get(position).id : -1l;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolderWithIcon viewHolderWithIcon = null;
		if (convertView == null)
		{
			convertView = minflater.inflate(R.layout.moreitem, null);
			viewHolderWithIcon = new ViewHolderWithIcon();
			viewHolderWithIcon.text = (TextView) convertView
					.findViewById(R.id.more_item_text);
			viewHolderWithIcon.icon = (ImageView) convertView
					.findViewById(R.id.more_item_icon);
			viewHolderWithIcon.sign = (ImageView) convertView
					.findViewById(R.id.more_item_sign);

			//synchronize with iphone
			viewHolderWithIcon.text.setTextColor(Color.BLACK);
			convertView.setDrawingCacheBackgroundColor(Color.WHITE);

			//synchronize with iphone

			/*   Drawable highLightImg = this.list.get(position).icon.getDrawable();
			highLightImg.setColorFilter(0xff000000, Mode.MULTIPLY);
			
			((ImageView)convertView.findViewById(R.id.more_item_icon)).setImageDrawable(highLightImg);*/
			viewHolderWithIcon.icon
					.setImageDrawable(this.list.get(position).icon
							.getDrawable());

			convertView.setTag(viewHolderWithIcon);
		}
		else
		{
			viewHolderWithIcon = (ViewHolderWithIcon) convertView.getTag();
		}

		/*  Drawable highLightImg = this.list.get(position).icon.getDrawable();
		  highLightImg.setColorFilter(0xff000000, Mode.MULTIPLY);*/

		viewHolderWithIcon.text.setText(this.list.get(position).text
				.getText());
		//		   viewHolderWithIcon.icon.setImageDrawable(highLightImg);
		viewHolderWithIcon.icon.setImageDrawable(this.list.get(position).icon
				.getDrawable());
		viewHolderWithIcon.sign.setImageResource(R.drawable.go_next_icon);
		return convertView;
	}

}
